package com.tuo51.evaluate.repositories.evaluatev2;

import com.tuo51.evaluate.domain.evaluatingV2.EvaluateV2Tool;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface EvaluateV2ToolRepository extends JpaRepository<EvaluateV2Tool, String> {

//    @Query(value = "select * from tb_evaluate_tool where questionId = :itemId", nativeQuery = true)
    List<EvaluateV2Tool> findAllByQuestionIdAndDeletedIsFalse(String questionId);

    @Query(value = "select t.* from tb_evaluate_tool t " +
            " left join tb_evaluate_question q on q.id = t.questionId " +
            " left join tb_evaluate_item i on i.id = q.itemId " +
            " where i.id = ?1  and t.deleted=0 order by q.indexOnPaper", nativeQuery = true)
    List<EvaluateV2Tool> findAllByItemIdAndDeletedIsFalse(String itemId);


    @Query(value = "SELECT t.* FROM tb_evaluate_tool t left join tb_evaluate_question q on t.questionId = q.id " +
            "where t.count > 0 order by q.indexOnPaper", nativeQuery = true)
    List<EvaluateV2Tool> findAllTools();
}
